package com.stephenone.zhdaily.homepage;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import com.asksira.loopingviewpager.LoopingPagerAdapter;
import com.bumptech.glide.Glide;
import com.stephenone.zhdaily.Constants;
import com.stephenone.zhdaily.R;
import com.stephenone.zhdaily.data.bean.News;
import com.stephenone.zhdaily.storydetail.StoryDetailActivity;

import java.util.ArrayList;

/**
 * Created by Administrator on 2018/1/11.
 */

public class TopStoryAdapter extends LoopingPagerAdapter<News.TopStory> {
    public TopStoryAdapter(Context context, ArrayList<News.TopStory> itemList, boolean isInfinite) {
        super(context, itemList, isInfinite);
    }

    @Override
    protected View inflateView(int viewType, int listPosition) {
        return LayoutInflater.from(context).inflate(R.layout.item_top_story_pager, null);
    }

    @Override
    protected void bindView(View convertView, int listPosition, int viewType) {
        ImageView imageView = convertView.findViewById(R.id.iv_background);
        TextView textView = convertView.findViewById(R.id.tv_top_title);
        Glide.with(context)
                .load(itemList.get(listPosition).getImage())
                .into(imageView);
        textView.setText(itemList.get(listPosition).getTitle());
        convertView.setOnClickListener((v) -> {
            Intent intent = new Intent(context, StoryDetailActivity.class);
            intent.putExtra(Constants.KEY_STORY_ID,itemList.get(listPosition).getId());
            context.startActivity(intent);
        });
    }
}
